 package controller;

import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import rmi.*;

public class Client {
	
	/* Creo una interfaz remota (conoce al Client y Server) con el nombre de Stub. el Stub es lo que el registry me manda a mi como cliente */
	private static RemoteInterface stub;
	
	public static void main(String[]  args) {  
		// set the security manager
	    //System.setSecurityManager(new RMISecurityManager());
		Registry registry; //added  
		try
	        { //obtener el objeto remoto del registry
	          //System.out.println("Security Manager loaded");
//	          String url = "//localhost/SAMPLE-SERVER";
//	          stub = (RemoteInterface) Naming.lookup(url);
	    	  
				registry = LocateRegistry.getRegistry(1099);//added
				stub = (RemoteInterface) registry.lookup("//localhost/SAMPLE-SERVER");//added
				System.out.println(stub.toString());//added

				System.out.println("Got remote object");
				System.out.println(" 1 + 2 = " + stub.sum(1,2) );
	        }
	        catch (RemoteException exc) {
	          System.out.println("Error in lookup: " + exc.toString()); }
//	        catch (java.net.MalformedURLException exc) {
//	          System.out.println("Malformed URL: " + exc.toString());   }
	        catch (java.rmi.NotBoundException exc)  {
	          System.out.println("NotBound: " + exc.toString());
	        }
	   }

}
